﻿using System;
using System.Configuration;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Navigant.Infrastructure;
using Navigant.Model.Cases;
using Navigant.Model.Custodians;
using Navigant.Model.PreservationNotices;

namespace Navigant.UnitTests.PreservationNoticeTemplates
{
    [TestClass()]
    public class PreservationNoticeTemplateTest
    {
        private TestContext testContextInstance;
        private Uri siteUri;
        private IUnitOfWork unitOfWork;

        public PreservationNoticeTemplateTest()
        {
            this.siteUri = new Uri(ConfigurationManager.AppSettings["testCaseSite"]);
            this.unitOfWork = new UnitOfWork();
        }

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return this.testContextInstance;
            }
            set
            {
                this.testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        /// <summary>
        ///A test for Merge
        ///</summary>
        [TestMethod()]
        public void MergeTest()
        {
            Case currentCase = CaseService.GetCaseBy(this.siteUri);
            PreservationNoticeTemplateService service = new PreservationNoticeTemplateService(currentCase, this.unitOfWork);
            PreservationNoticeTemplate template = service.FindAll()[0];
            CustodianService custodianService = new CustodianService(currentCase, this.unitOfWork);
            Custodian custodian = custodianService.FindAll()[0];
            PreservationNotice notice = template.Merge(custodian, false, "tmccart1@san.rr.com");
            this.testContextInstance.WriteLine("To:  {0}", notice.To.Email);
            this.testContextInstance.WriteLine("From:  {0}", notice.FromAddress);
            this.testContextInstance.WriteLine("Subject:  {0}", notice.Subject);
            this.testContextInstance.WriteLine(notice.Body);
            Assert.AreEqual(notice.TemplateId, template.Id);
        }
    }
}
